package com.syni.mdd.sjb.common.datatreaure.controller.protect;

import com.syni.mdd.sjb.common.component.utils.common.annotations.CheckUserIdentity;
import com.syni.mdd.sjb.common.component.utils.common.utils.ResultMapHelper;
import com.syni.mdd.sjb.common.component.utils.feign.dto.mddAll.apiUser.GetIdentifyingCodeDto;
import com.syni.mdd.sjb.common.component.utils.feign.service.mddAll.BusinessRestService;
import com.syni.mdd.sjb.common.datatreaure.controller.BaseController;
import com.syni.mdd.sjb.common.datatreaure.entity.vo.rp.FeedbackVo;
import com.syni.mdd.sjb.common.datatreaure.entity.vo.rq.BaseRqVo;
import com.syni.mdd.sjb.common.datatreaure.entity.vo.rq.user.*;
import com.syni.mdd.sjb.common.datatreaure.entity.vo.rq.userChannel.SwitchQuickAccessVo;
import com.syni.mdd.sjb.common.datatreaure.service.DxshAppFeedbackService;
import com.syni.mdd.sjb.common.datatreaure.service.DxshAppUserChannelService;
import com.syni.mdd.sjb.common.datatreaure.service.UserService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cfx
 * @since 2020-04-20
 */
@RestController
@RequestMapping("/auth")
@RefreshScope
@Log4j2
public class UserController extends BaseController {

    @Autowired
    UserService userService;

    @Autowired
    DxshAppFeedbackService dxshAppFeedbackService;

    @Autowired
    DxshAppUserChannelService dxshAppUserChannelService;
    @Autowired
    BusinessRestService businessRestService;


    @PostMapping("/register")
    @ApiOperation(value = "电享生活商户端App注册")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone",value = "手机号"),
            @ApiImplicitParam(name = "verificationCode",value = "验证码"),
            @ApiImplicitParam(name = "password",value = "注册密码")})
    public Map<String,Object> register(@RequestBody @Validated RegisterVo registerVo){
        //ModelAndView modelAndView = new ModelAndView();
        //modelAndView.setView(new RedirectView("a"));

        return userService.register(registerVo);
    }

    @PostMapping("/register/v2")
    @ApiOperation(value = "电享生活商户端App注册")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone",value = "手机号"),
            @ApiImplicitParam(name = "verificationCode",value = "验证码"),
            @ApiImplicitParam(name = "password",value = "注册密码")})
    public Map<String,Object> register_v2(@RequestBody @Validated RegisterVo registerVo){
        //ModelAndView modelAndView = new ModelAndView();
        //modelAndView.setView(new RedirectView("a"));
        return userService.register_v2(registerVo);
    }

    @PostMapping("/login")
    @ApiOperation(value = "电享生活商户端App登陆")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone", value = "手机号"),
            @ApiImplicitParam(name = "loginWay", value = "登陆类型 1验证码 2密码"),
            @ApiImplicitParam(name = "loginBody", value = "密码/验证码")
    })
    public Map<String,Object> login(@RequestBody @Validated LoginVo loginVo){
        return userService.login(loginVo);
    }

    @PostMapping("/forget")
    @ApiOperation(value = "忘记密码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone", value = "手机号"),
            @ApiImplicitParam(name = "password",value = "新密码"),
            @ApiImplicitParam(name = "identifyCode",value = "验证码")
    })
    public Map<String,Object> forget(@RequestBody @Validated ForgetVo forgetVo){return userService.forget(forgetVo);}

    @PostMapping("/getIdentifyingCode")
    @ApiOperation(value = "获取验证码" , notes = "201注册 202忘记密码 203登陆")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone", value = "手机号"),
            @ApiImplicitParam(name = "codeType",value = "验证码类型"),
    })
    public Map<String,Object> getIdentifyingCode(@RequestBody @Validated GetIdentifyingCodeDto getIdentifyingCodeDto){
        return userService.getIdentifyingCode(getIdentifyingCodeDto);
    }

    @PostMapping("/saveUserInfo")
    @ApiOperation(value = "保存用户个人资料")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "headImg",value = "头像URL"),
            @ApiImplicitParam(name = "surName",value = "姓氏"),
            @ApiImplicitParam(name = "name",value = "名字"),
            @ApiImplicitParam(name = "sex",value = "性别"),
            @ApiImplicitParam(name = "age",value = "年龄")
    })
    @CheckUserIdentity
    public Map<String,Object> saveUserInfo(@RequestBody @Validated SaveUserInfoVo saveUserInfoVo){
        return userService.saveUserInfo(saveUserInfoVo);
    }

    @PostMapping("/modifyPwd")
    @ApiOperation(value = "修改用户密码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "identifyCode",value = "验证码"),
            @ApiImplicitParam(name = "newPwdA",value = "新密码A"),
            @ApiImplicitParam(name = "newPwdB",value = "新密码B")
    })
    @CheckUserIdentity
    public Map<String,Object> modifyPwd(@RequestBody @Validated ModifyPwdVo modifyPwdVo){
        return userService.modifyPwd(modifyPwdVo);
    }

    @PostMapping("/feedback")
    @ApiOperation(value = "问题反馈")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "content",value = "建议内容"),
            @ApiImplicitParam(name = "screenshot",value = "相关截图")
    })
    @CheckUserIdentity
    public Map<String,Object> feedback(@RequestBody @Validated FeedbackVo feedbackVo){
        return dxshAppFeedbackService.feedback(feedbackVo);
    }

    @PostMapping("/getQuickAccessList")
    @ApiOperation(value = "获取快捷访问列表")
    @ApiImplicitParams({
    })
    @CheckUserIdentity
    public Map<String,Object> getQuickAccessList(@RequestBody BaseRqVo baseRqVo){
        return dxshAppUserChannelService.getQuickAccessList(baseRqVo);
    }

    @PostMapping("/switchQuickAccess")
    @ApiOperation(value = "开启或关闭首页的快捷访问")
    @ApiImplicitParams({
    })
    @CheckUserIdentity
    public Map<String,Object> switchQuickAccess(@RequestBody @Validated SwitchQuickAccessVo switchQuickAccessVo){
        return dxshAppUserChannelService.switchQuickAccess(switchQuickAccessVo);
    }

    @PostMapping("/getOneTimeToken")
    @ApiOperation(value = "获取一次性token")
    @ApiImplicitParams({})
    @CheckUserIdentity
    public  Map<String,Object> getOneTimeToken(@RequestBody BaseRqVo baseRqVo){
        return userService.getOneTimeToken(baseRqVo);
    }

    //@GetMapping("/test")
    //public Map<String,Object> d(@RequestBody Test test){
        /*GetMddBusinessDataByDxshAppDto getMddBusinessDataByDxshAppDto = new GetMddBusinessDataByDxshAppDto();
        Set<Integer> businessIds = new HashSet<>();
        businessIds.add(4520);
        businessIds.add(5670);
        getMddBusinessDataByDxshAppDto.setBusinessIds(businessIds);
        RpcResponseVo rpcResponseVo = businessRestService.getMddBusinessDataByDxshApp(getMddBusinessDataByDxshAppDto);
        if(rpcResponseVo.isSuccess()){
            getMddBusinessDataByDxshAppDto = rpcResponseVo.parseObject(GetMddBusinessDataByDxshAppDto.class);
            return ResultMapHelper.success(getMddBusinessDataByDxshAppDto,"a");
        }*/
//        System.out.println(testProperties);
//        System.out.println(opq);
    //    System.out.println("test"+test.getUserid());
    //    return ResultMapHelper.result("a","a");
    //}

    @PostMapping("/test")
    public Map<String,Object> td(@RequestParam("name") String name,@RequestParam("age") Integer age) {
        log.info("age {} ",age);
        log.info("name {} ",name);
        return ResultMapHelper.success();
    }
}
